package com.unusap.remote.core.remote.http;

import com.unusap.remote.core.remote.factory.HttpHeadersProvider;

import java.net.URLConnection;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: danson
 * Date: 2009-8-21
 * Time: 10:39:34
 * To change this template use File | Settings | File Templates.
 */
public class DefaultURLConnectionPropertySetter implements URLConnectionPropertySetter {

    private URLConnection connection;
    private HttpHeadersProvider httpHeadersProvider;

    public DefaultURLConnectionPropertySetter(URLConnection connection, HttpHeadersProvider httpHeadersProvider) {
        this.httpHeadersProvider = httpHeadersProvider;
        this.connection = connection;
    }

    public void execute() {
        Map<String,String> headers = httpHeadersProvider.getHeaders();
        if (headers != null) {
            for (Map.Entry<String, String> entry : headers.entrySet()) {
                connection.setRequestProperty(entry.getKey(), entry.getValue());
            }
        }
    }
}
